#include "rtda/heap/cp_methodref.h"
#include "classfile/class_file.hpp"
#include "rtda/heap/method.h"
#include <memory>

namespace jvm {
namespace heap {

MethodRef::MethodRef(std::shared_ptr<ConstantPool> pCp, const std::shared_ptr<classfile::ConstantMethodRefInfo> pMemberrefInfo) 
    : MemberRef(pCp) {
    copyMemberRefInfo(pMemberrefInfo);
}

std::shared_ptr<MethodRef> MethodRef::newMethodRef(std::shared_ptr<ConstantPool> pCp, 
    const std::shared_ptr<classfile::ConstantMethodRefInfo> pMethodrefInfo) {
    return std::make_shared<MethodRef>(pCp, pMethodrefInfo);
}

std::shared_ptr<Method> MethodRef::resolvedMethod() {
    if (!m_pMethod) {
        resolveMethodRef();
    }
    return m_pMethod;
}

void MethodRef::resolveMethodRef() {
    // TODO: Implement method resolution according to JVMS 5.4.3.3
    // Class* pClass = resolvedClass();
    // ...
}

} // namespace heap
} // namespace jvm